package cn.com.dashihui.api.common;

import com.jfinal.kit.PropKit;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.redis.RedisPlugin;

import redis.clients.jedis.JedisPool;

public class ESRedisPlugin {
	private static String host;
	private static int port;
	private static int timeout;//  过期时间 单位 秒
	private static String password;
	private static int maxTotal;//  设置最大实例总数
	private static int maxIdle;//  空闲数
	private static int maxWait;//   等待时间 单位 ： 秒
	public static String defualtCacheName = "redis";// 默认cacheName
	private static RedisPlugin redisPlugin;
	
	// 连接池
    protected static JedisPool pool;
	
	

	public static RedisPlugin config(){
		try {
			host = PropKit.get("redis_host").trim();
			port = Integer.valueOf(PropKit.get("redis_port").trim());
			timeout = Integer.valueOf(PropKit.get("redis_timeout").trim());
			password=null!=PropKit.get("redis_password")?PropKit.get("redis_password").trim():null;
			maxTotal = Integer.valueOf(PropKit.get("redis_maxTotal").trim());
			maxIdle = Integer.valueOf(PropKit.get("redis_maxIdle").trim());
			maxWait = Integer.valueOf(PropKit.get("redis_maxWait").trim());

			if (StrKit.notBlank(password)) {
				redisPlugin = new RedisPlugin(defualtCacheName, host, port, timeout * 1000, password);
			} else {
				redisPlugin = new RedisPlugin(defualtCacheName, host, port, timeout * 1000);
			}
			redisPlugin.getJedisPoolConfig().setMaxTotal(maxTotal);
			redisPlugin.getJedisPoolConfig().setMaxIdle(maxIdle);
			redisPlugin.getJedisPoolConfig().setMaxWaitMillis(maxWait * 1000);
			return redisPlugin;
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			return redisPlugin;
		}
	}
	
	






}
